<%
layout("/layouts/platform.html"){
%>
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-primary navbar-btn" href="${base}/platform/wx/reply/news" id="goback" data-pjax><i class="ti-angle-left"></i> 返回</a>
    </div>
</header>

<div class="content-wrap">
    <div class="wrapper" style="min-height:500px;">
        <section class="panel panel-form">
            <form id="addForm" role="form" class="form-horizontal parsley-form" data-parsley-validate
                  action="${base}/platform/wx/reply/news/editDo" method="post">
                <input type="hidden" name="id" value="${obj.id!}">
                <div class="row mb10">
                    <div class="col-lg-12">
                        <div class="form-group">
                            <label for="title" class="col-sm-2 control-label">标题</label>

                            <div class="col-sm-8">
                                <input type="text" id="title" class="form-control" name="title" data-parsley-required="true"
                                       placeholder="标题" value="${obj.title!}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="description" class="col-sm-2 control-label">摘要</label>

                            <div class="col-sm-8">
                                <textarea id="description" name="description" cols="60" rows="6" data-parsley-required="true">${obj.description!}</textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="picUrl" class="col-sm-2 control-label">标题图</label>
                            <div class="col-sm-8">
                                <div id="queue"></div>
                                <div>
                                    <input id="file_upload" name="file_upload" type="file" multiple="false">
                                </div>
                                <div id="img" style="padding: 5px;">
                                    <%if(!isEmpty(obj.picUrl)){%>
                                    <img src='${obj.picUrl!}' style='width:150px;height:95px;'>
                                    <%}%>
                                </div>
                                <input type="hidden" id="picUrl" name="picUrl" value="${obj.picUrl!}" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="url" class="col-sm-2 control-label">链接地址</label>
                            <div class="col-sm-8">
                                <input type="text" id="url" class="form-control" name="url" data-parsley-required="true"
                                       placeholder="链接地址" value="${obj.url!}">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-3"></div>
                <div class="col-lg-6">
                    <div class="form-group text-center">
                        <label></label>

                        <div>
                            <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
                        </div>
                    </div>
                </div>
            </form>
        </section>

    </div>
</div>
<script language="JavaScript">
    function clearFile() {
        $("#img").html("");
        $("#queue").html("");
        $("#picUrl").val("");
    }
    $(document).ready(function () {
        $('#file_upload').uploadifive({
            'auto': true,
            'multi': false,
            'width': '100%',
            'height': '35',
            'buttonText': '请选择图片',
            'fileType': 'image/jpg,image/jpeg,image/png',
            'fileSizeLimit': 1024,
            'queueSizeLimit': 1,
            'formData': {},
            'queueID': 'queue',
            'uploadScript': '${base}/open/file/upload/image',
            'onUploadComplete': function (file, data) {
                data = JSON.parse(data);
                if (data.code == 0) {
                    Toast.success(data.msg);
                    $("#img").html("<img src='" + data.data + "' style='width:150px;height:95px;'>");
                    $("#picUrl").val('${AppDomain}${base}'+data.data);
                } else {
                    clearFile();
                    Toast.error(data.msg);
                }
            },
            'onDrop': function (file, fileDropCount) {
                clearFile();
            },
            'onClearQueue': function (queue) {
                clearFile();
            },
            'onCancel': function () {
                clearFile();
            }
        });
        $('#addForm').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (arr, form, options) {
                form.find("button:submit").button("loading");
            },
            success: function (data, statusText, xhr, form) {
                if (data.code == 0) {
                    Toast.success(data.msg);
                    //刷新父级菜单
                    setTimeout(function () {
                        $("#goback").trigger("click");
                    }, 1000);
                } else {
                    Toast.error(data.msg);
                }
                form.find("button:submit").button("reset");
            }
        });
    });
</script>


<%}%>